SSI: Failed String Comparison with CGI Environment Variable [migrated]
Posted
by
Calyo Delphi
on Pro Webmasters
See other posts from Pro Webmasters
or by Calyo Delphi
Published on 2012-11-09T05:44:31Z
Indexed on
2012/11/09
11:22 UTC
Read the original article
Hit count: 211
web-development
|bugs
I am currently working on developing a personal website. It's not my first time doing this, but this is my first major foray into implementing SSI. I've run myself into a wall, however, with an if-else directive that uses one of the CGI environment variables as part of its comparison.
Even after some limited attempts at debugging, all of the output and documentation that I have means that the comparisons being made should fail outright. This is not the case, and the wrong evaluation is being made by the if-else directive.
Here's the code in the file index.shtml
:
<head>
<!--#set var="page" value="Home" -->
<!--#include file="headlinks.shtml" -->
<style>
img#ref { float: right; margin-left: 8px; border-width: 0px; }
</style>
</head>
Here's the code in the file headlinks.shtml
:
<title><!--#echo var="page" --> – <!--#echo var="HTTP_HOST" --></title>
<!--#set var="docroot" value="${DOCUMENT_ROOT}" -->
<!--#echo var="docroot" -->
<!--#if expr="( $docroot != '/Applications/MAMP/htdocs' ) || ( $docroot != '/home/dragarch/public_html' )" -->
<link rel="stylesheet" type="text/css" href="../style.css">
<link rel="shortcut icon" type="image/svg+xml" href="../favicon.svg" />
<!--#else -->
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="shortcut icon" type="image/svg+xml" href="favicon.svg" />
<!--#endif -->
And here's the output for the file index.shtml
:
<title>Home – dragarch</title>
/Applications/MAMP/htdocs
<link rel="stylesheet" type="text/css" href="../style.css">
<link rel="shortcut icon" type="image/svg+xml" href="../favicon.svg" />
Both style.css
and favicon.svg
are in the document root with index.shtml
, so the if directive should fail and default to the output of the else directive. As you can see, while the document root (which is currently the MAMP htdocs folder on my own notebook) is correct according to the output of the echo directive, the comparison in the if-else directive fails to compare the strings properly.
I'm using this page for my documentation: http://httpd.apache.org/docs/2.2/mod/mod_include.html
I'm at a complete loss as to why this is the case, and need a bit of help here.
EDIT: I should note that dragarch
is a hostname that I configured in /etc/hosts
to point to 127.0.0.1 so I could test the site without having to use localhost
. It has no real effect on the functionality of anything, other than to just act as a prettier hostname to use.
© Pro Webmasters or respective owner